/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package a1;

/**
 *
 * @author azka
 */
public class MainUI {

    private ProjectModel trafficMod = new ProjectModel();
    private userInput input = new userInput();
    private Grid gr = new Grid(trafficMod);
    /** Show menu to the user and prompt the user to input choice */
    public void showMenu() {


        int x = 1;
        while (x > 0) {
            
            System.out.print(" === MENU ===\n"
                    + " 1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n"
                    + " 2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n"
                    + " 3. Set Probability of a car entering H-street [min 0, max 1]\n"
                    + " 4. Set Probability of a car entering V-street [min 0, max 1]\n"
                    + " 5. Run one simulation cycle\n"
                    + " 6. Set and run number of simulation cycles [min 1, max 10]\n"
                    + " ");
            String choice = input.getInput("Enter your choice:");
            int choiceInt = Integer.parseInt(choice);

            switch (choiceInt) {
                case 1:
                    System.out.println("\nMenu 1 chosen");
                    menu1();
                    break;
                case 2:
                    System.out.println("\nMenu 2 chosen");
                    menu2();
                    break;
                case 3:
                    System.out.println("\nMenu 3 chosen");
                    menu3();
                    break;
                case 4:
                    System.out.println("\nMenu 4 chosen");
                    menu4();
                    break;
                case 5:
                    System.out.println("\nMenu 5 chosen");
                    menu5();
                    break;
                case 6:
                    System.out.println("\nMenu 6 chosen");
                    menu6();

                    break;
            }
        }

    }

    /** Method for if menu 1 is chosen */
    public void menu1() {

      
        String choice = input.getInput("Enter number of horizontal lane [1-3]:");
        int inputInt = Integer.parseInt(choice);

        if (inputInt < 1 || inputInt > 3) {
            System.out.println("Error! Input number from 1 - 3");
            showMenu();
        } else {
            trafficMod.setHor(inputInt);
            System.out.println("Horizontal lane set to " + inputInt);
           
            gr.buildLanes();
            
        }



    }
/** Method for if menu 2 is chosen */
    public void menu2() {
        
        String choice = input.getInput("Enter number of vertical lane [1-4]:");
        int inputInt = Integer.parseInt(choice);

        if (inputInt < 1 || inputInt > 4) {
            System.out.println("Error! Input number from 1 - 4");
            showMenu();
        } else {
            trafficMod.setVer(inputInt);
            System.out.println("Vertical lane set to " + inputInt);
            
           gr.buildLanes();

        }


    }
/** Method for if menu 3 is chosen */
    public void menu3() {
        
        String choice = input.getInput("Enter probability car on H-Lanes[0-1]:");
        double inputDouble = Double.parseDouble(choice);

        if (inputDouble > 1 || inputDouble < 0) {
            System.out.println("Error! Input number from 0 - 1");
            showMenu();
        } else {
            trafficMod.setHorProb(inputDouble);
            System.out.println("Probability of horizontal car is " + trafficMod.getHorProb());


        }
    }
/** Method for if menu 4 is chosen */
    public void menu4() {
       
        String choice = input.getInput("Enter probability car on V-Lanes[0-1]:");
        double inputDouble = Double.parseDouble(choice);

        if (inputDouble > 1 || inputDouble < 0) {
            System.out.println("Error! Input number from 0 - 1");
            showMenu();
        } else {
            trafficMod.serVerProb(inputDouble);
            System.out.println("Probability of vertical car is " + trafficMod.getVerProb());



        }
    }
/** Method for if menu 5 is chosen */
    public void menu5() {
        
        gr.runCycle(trafficMod, 1);
    }
/** Method for if menu 6 is chosen */
    public void menu6() {

        
        String choice = input.getInput("Enter number of simulation cycle [1-10]:");
        int inputInt = Integer.parseInt(choice);

        if (inputInt > 10 || inputInt < 1) {
            System.out.println("Error! Input number from 1 - 10");
            showMenu();
        } else {
            
            gr.runCycle(trafficMod, inputInt);
        }
    }
}
